<% layout('/layouts/default.html', {title: '出入库单管理', libs: ['validate','dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header with-border">
			<div class="box-title">
				<i class="fa icon-note"></i> ${text(stInventoryBill.isNewRecord ? '新增出入库单' : '编辑出入库单')}
			</div>
			<script src="https://cdn.bootcdn.net/ajax/libs/bignumber.js/9.0.1/bignumber.js"></script>
			<div class="box-tools pull-right">
				<a href="#" class="btn btn-default" id="btn-src" ><i class="fa fa-filter"></i> ${text('源单')}
				</a>
				<a href="#" class="btn btn-default" id="btn-approve" ><i class="fa fa-filter"></i> ${text('审核')}
				</a>
				<a href="#" class="btn btn-default" id="btn-revocation" ><i class="fa fa-filter"></i> ${text('弃审')}
				</a>
				<a href="#" class="btn btn-default" id="btn-save" ><i class="fa fa-filter"></i> ${text('保存')}
				</a>

				<script>
					var aStatus=${stInventoryBill.approveState!"null"};
					approveBtnStatus(aStatus);
					function approveBtnStatus(status) {
						var $save=$("#btn-save");
						var $approve=$("#btn-approve");
						var $revocation=$("#btn-revocation");
						if (null == status ) {
							$save.show();
							$approve.hide();
							$revocation.hide();
						}
						if (2 == status) {
							$save.show();
							$approve.show();
							$revocation.hide();
						}
						if (4 == status) {
							$save.hide();
							$approve.hide();
							$revocation.show();
						}
					}
					$("#btn-save").click(function () {
						$("#approveState").val(2);
						$("form").submit();
					});
					function refresh(id) {
						location.replace("${ctx}/st/stInventoryBill/saleOutForm?id="+id);
						// location.reload();
					}
					$("#btn-revocation").click(function () {
						var id=$("#id").val();
						console.info("id", id);
						$.ajax({
							url:"${ctx}/st/stInventoryBill/approve",
							dataType:'json',
							type:'POST',
							data:{
								//请求参数
								id:id,
								approveStatus:2,
							},
							success:function(result){
								if (1 != result.code) {
									js.showMessage(result.data);
									return;
								}
								js.showMessage("弃审，替换");
							}
						});
					});
					$("#btn-src").click(function (){
						var custom = $("#supplierId").val();
						if(""==custom.trim()){
							js.showMessage("没选择客户");
						}else{
							$("#btn-src-0Div").attr("data-url", "${ctx}/st/stSendNoticeBill/forChoose?custom=" + custom);
							$("#btn-src-0Button").click();
						}
					});

					// 审核-------------------------------
					$("#btn-approve").click(function () {
						var id=$("#id").val();
						$.ajax({
							url:"${ctx}/st/stInventoryBill/approve",
							dataType:'json',
							type:'POST',
							data:{
								//请求参数
								id:id,
								approveStatus:4,//具体是几还待确定
							},
							success:function(result){
								if (1 != result.code) {
									js.showMessage(result.data);
									return;
								}
								js.showMessage("审核成功，此处替换成盖章");
							}
						});
					});

					function chooseSale(id, act, index, layero, selectData){
						var selectLength = selectData.length;
						var idArr = [];
						for (var i = 0; i < selectLength; i++) {
							idArr.push(selectData[i].id);
						}
						$(".del").click();
						$.ajax({
							url:"${ctx}/st/stSendNoticeBill/findDetail",
							dataType:'json',
							type:'POST',
							data:{
								//请求参数
								id: idArr.join(",")
							},
							success:function(result){
								console.info(result);
								for(var i=0;i<result.length;i++){
									$("#stInventoryBillDetailDataGridAddRowBtn").click();
									var item = result[i];
									var materialName = $(($(($("#stInventoryBillDetailDataGrid").find("tr"))[1 + i/*+ t_size_1 + formula_list.length + pre_mix*/]).find('td'))[3]);
									materialName.find(".form-control").val(item.materialName).trigger('change');
									materialName.find("input[name=materialName]:hidden").val(item.materialName).attr("code",item.stProductRecord.productCode)
									.attr("m-name",item.stProductRecord.productName).attr("number",item.number);
									var unit = materialName.next();
									unit.find(".form-control").val(item.unit);
									var number = unit.next();
									number.find(".form-control").val(0);
									var caseNumber = number.next();
									caseNumber.find(".form-control").val(0)
									var primaryId =caseNumber.next().next();
									primaryId.find(".form-control").val(item.id);
								}
							}
						});

					}
				</script>
				<div class="hide">
					<#form:listselect id="btn-src-0" title="销售单"

					url="${ctx}/st/stPurchaseBill/list" allowClear="false"
					checkbox="false"  callbackFuncName="chooseSale"/>
				</div>
				<a href="#" class="btn btn-default" id="btnSetting" title="${text('设置')}"><i class="fa fa-navicon"></i></a>
				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
			</div>
		</div>
		<#form:form id="inputForm" model="${stInventoryBill}" action="${ctx}/st/stInventoryBill/save" method="post" class="form-horizontal">
			<div class="box-body">
				<div class="form-unit">${text('基本信息')}</div>

				<#form:hidden path="id"/>
				<div class="row">
<!--					<div class="col-xs-6">-->
<!--						<div class="form-group">-->
<!--							<label class="control-label col-sm-4" title="">-->
<!--								<span class="required hide">*</span> ${text('单据号')}：<i class="fa icon-question hide"></i></label>-->
<!--							<div class="col-sm-8">-->
<!--								<#form:input path="billNo" maxlength="20" class="form-control"/>-->
<!--							</div>-->
<!--						</div>-->
<!--					</div>-->
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('单据日期')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="billDate" readonly="true" maxlength="20" class="form-control laydate"
									dataFormat="datetime" data-type="datetime" data-format="yyyy-MM-dd HH:mm"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('单据类别')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="billType" dictType="st_stock_in_bill_type" blankOption="true" class="form-control digits" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('入账日期')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="tallyDate" readonly="true" maxlength="20" class="form-control laydate"
									dataFormat="datetime" data-type="datetime" data-format="yyyy-MM-dd HH:mm"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('条码扫描')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="barCode" class="form-control"/>
								<script>
									var Base64 = {
										_keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
										encode: function(e) {
											var t = "";
											var n, r, i, s, o, u, a;
											var f = 0;
											e = Base64._utf8_encode(e);
											while (f < e.length) {
												n = e.charCodeAt(f++);
												r = e.charCodeAt(f++);
												i = e.charCodeAt(f++);
												s = n >> 2;
												o = (n & 3) << 4 | r >> 4;
												u = (r & 15) << 2 | i >> 6;
												a = i & 63;
												if (isNaN(r)) {
													u = a = 64
												} else if (isNaN(i)) {
													a = 64
												}
												t = t + this._keyStr.charAt(s) + this._keyStr.charAt(o) + this._keyStr.charAt(u) + this._keyStr.charAt(a)
											}
											return t
										},
										decode: function(e) {
											var t = "";
											var n, r, i;
											var s, o, u, a;
											var f = 0;
											e = e.replace(/[^A-Za-z0-9+/=]/g, "");
											while (f < e.length) {
												s = this._keyStr.indexOf(e.charAt(f++));
												o = this._keyStr.indexOf(e.charAt(f++));
												u = this._keyStr.indexOf(e.charAt(f++));
												a = this._keyStr.indexOf(e.charAt(f++));
												n = s << 2 | o >> 4;
												r = (o & 15) << 4 | u >> 2;
												i = (u & 3) << 6 | a;
												t = t + String.fromCharCode(n);
												if (u != 64) {
													t = t + String.fromCharCode(r)
												}
												if (a != 64) {
													t = t + String.fromCharCode(i)
												}
											}
											t = Base64._utf8_decode(t);
											return t
										},
										_utf8_encode: function(e) {
											e = e.replace(/rn/g, "n");
											var t = "";
											for (var n = 0; n < e.length; n++) {
												var r = e.charCodeAt(n);
												if (r < 128) {
													t += String.fromCharCode(r)
												} else if (r > 127 && r < 2048) {
													t += String.fromCharCode(r >> 6 | 192);
													t += String.fromCharCode(r & 63 | 128)
												} else {
													t += String.fromCharCode(r >> 12 | 224);
													t += String.fromCharCode(r >> 6 & 63 | 128);
													t += String.fromCharCode(r & 63 | 128)
												}
											}
											return t
										},
										_utf8_decode: function(e) {
											var t = "";
											var n = 0;
											var r = c1 = c2 = 0;
											while (n < e.length) {
												r = e.charCodeAt(n);
												if (r < 128) {
													t += String.fromCharCode(r);
													n++
												} else if (r > 191 && r < 224) {
													c2 = e.charCodeAt(n + 1);
													t += String.fromCharCode((r & 31) << 6 | c2 & 63);
													n += 2
												} else {
													c2 = e.charCodeAt(n + 1);
													c3 = e.charCodeAt(n + 2);
													t += String.fromCharCode((r & 15) << 12 | (c2 & 63) << 6 | c3 & 63);
													n += 3
												}
											}
											return t
										}
									}
									$("#barCode").bind("keydown",function(event) {

										if (event.keyCode == "13") {
											var barCode = $("#barCode").val();

											var bc = barCode.split("_")[0];
											var batch_1 = barCode.split("_")[1];
											var $code = $("[code=" + bc + "]");
											if(0==$code.size()){
												js.showMessage("扫码物品出错");
												return false;
											}
											if(1<$code.size()){
												js.showMessage("请出两个单子");//todo 这个东西不能做这么死
												return false;
											}


											var batchList=$("#batchs").data("batch");
											if (!batchList) {
												batchList = $("#batchs").val();
												if(!batchList) batchList = [];
												else batchList = batchList.split(",");
												$("#batchs").data("batch",batchList);
											}
											//
											if (-1 != batchList.indexOf(batch_1)) {
												js.showMessage("该批次已经存在");
												return false;
											}
											var materialCode = bc;
											function chooseWarehouse(){
												js.layer.open({
													type: 2,
													area: ['400px', '500px'],
													title: '${text("选择仓位")}',
													resize: false,
													scrollbar: true,
													content: "${ctx}/st/stProductMaterialFormBill/scanView0?materialCode=" + materialCode + "&batchNumber=" + batch_1,
													success: function (layero, index) {
														layero.find('input[type="checkbox"]').iCheck();
													},
													btn: ['<i class="fa fa-check"></i> ${text("导入")}',
														'<i class="fa fa-remove"></i> ${text("关闭")}'],
													btn1: function (index, layero) {
														// var form = {
														// 	warehouseNumber: layero.find('#warehouseNumber').val(),
														// 	file: layero.find('#file').val()
														// };
														// console.info("index", index);
														// var frameId = $(layero).find("iframe").attr('id');
														// var iframeWin = window.frames[frameId]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
														// var iframeWin = window[layero.find('iframe')[0]['name']];
														var win = layero.iframeWindow();
														var params = win.commit();
														scanOpen(params.warehouseId,params.number);
														// openChoose(params.warehouseId,params.number);
														// js.ajaxSubmitForm(form.inputForm, function(data){
														// 	js.showMessage(data.message);
														// 	if(data.result == Global.TRUE){
														// 		js.layer.closeAll();
														// 	}
														// 	page();
														// }, "json");
														return true;
													}
												});
											}

											function scanOpen(warehouseId,warehouseNumber) {//如果过期就不需要弹框了
												js.layer.open({
													type: 2,
													area: ['400px', '500px'],
													title: '${text("物料选择")}',
													resize: false,
													scrollbar: true,
													content: "${ctx}/st/stInventoryBill/materialChoose?needNumber=" + $code.attr("number") + "&warehouseNumber=" + warehouseNumber,
													success: function (layero, index) {
														layero.find('input[type="checkbox"]').iCheck();
													},
													btn: ['<i class="fa fa-check"></i> ${text("导入")}',
														'<i class="fa fa-remove"></i> ${text("关闭")}'],
													btn1: function (index, layero) {
														var win = layero.iframeWindow();
														var params = win.commit();
														console.info(params);
														if (-1 != params.caseNumber.indexOf(".") || '' == params.caseNumber || '' == params.getNumber) {
															js.showMessage("检查填写的数据");
															return false;
														}
														var $code = $("[code=" + bc + "]");
														var commitList = [];
														$.each($code, function (i, item) {
															// <input name='materialName' code='' my-sort='"+index+"' m-name='' value='"+element.value+"' hidden>

															var code = $(item).attr("code");
															var sort = $(item).attr("my-sort");
															var id = sort;
															var materialName = $(item).attr("m-name");
															var numberTD = $(item).closest("td").next().next();
															var number = numberTD.find(".form-control").val();
															commitList.push({
																id,
																code,
																sort,
																materialName,
																number,
															});
														});
														var json = JSON.stringify(commitList);
														if ($code.size() > 1) {
															js.layer.open({
																type: 2,
																area: ['400px', '500px'],
																title: '${text("物料选择")}',
																resize: false,
																scrollbar: true,
																content: "${ctx}/st/stInventoryBill/tableChoose?json=" + Base64.encode(json),
																success: function (layero, index) {
																	layero.find('input[type="checkbox"]').iCheck();
																},
																btn: ['<i class="fa fa-check"></i> ${text("导入")}',
																	'<i class="fa fa-remove"></i> ${text("关闭")}'],
																btn1: function (index, layero) {
																	var win = layero.iframeWindow();
																	var paramsT = win.commit();
																	if (!paramsT) {
																		js.showMessage("请选择");
																		return false;
																	}
																	setValue(paramsT, params,null,batch_1,warehouseId);
																	return true;
																}
															});
														} else {//只取到一个
															setValue(null, params, $code, batch_1,warehouseId);
														}

														return true;
													}
												});
											}
											$.ajax({
												url:"${ctx}/st/stStockCheckBill/isCheck",
												dataType:'json',
												type:'POST',
												data:{
													//请求参数
													batchNumber:batch_1
												},
												success:function(result){
													console.info(result);
													if (1 != result.code) {
														js.showMessage(result.data);
														return;
													}
													// scanOpen();
													chooseWarehouse();
												}
											});

											return false;
										}

									});
									function setValue(paramsT,params,$code,batch_1,warehouseId) {
										var $materialName = null;
										if(paramsT) $materialName = $("[my-sort=" + paramsT.sort + "]").closest("td");
										if($code) $materialName = $code.closest("td");

										var number = $materialName.next().next();
										var n1=number.find(".form-control").val();
										number.find(".form-control").val(parseInt(params.getNumber) + parseInt(n1));
										var caseNumber = number.next();

										var n_case=caseNumber.find(".form-control").val();
										caseNumber.find(".form-control").val(parseInt(params.caseNumber ) + parseInt(n_case));
										var $batch = number.next().next();
										var batch = $batch.find("[name=batchNumber]").data("batch");
										var batch_source = batch_1;
										if(!batch) batch=[];
										batch.push(warehouseId+"_"+batch_source+"_"+params.getNumber);
										$batch.find("[name=batchNumber]").data("batch", batch);
										var batch_value = batch.join(",");
										$batch.find("[name=batchNumber]").val(batch_value);
										console.info(batch_value);
										var batchList=$("#batchs").data("batch");//一定是有值的
										batchList.push(batch_source);
										$("#batchs").data("batch", batchList);
										$("#batchs").val(batchList.join(","));
									}
								</script>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('客户')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="supplierId" items="${customList}" itemLabel="companyFullName" blankOption="true" itemValue="id" class="form-control required" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('源单')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="primaryBillNo" maxlength="20" class="form-control"/>
							</div>
						</div>
					</div>

					<#form:hidden path="inOrOut" defaultValue="33"/>
					<#form:hidden path="approveState"/>
<!--					<div class="col-xs-6">-->
<!--						<div class="form-group">-->
<!--							<label class="control-label col-sm-4" title="">-->
<!--								<span class="required hide">*</span> ${text('出库或入库')}：<i class="fa icon-question hide"></i></label>-->
<!--							<div class="col-sm-8">-->
<!--								<#form:select path="inOrOut" dictType="st_inventory_bill_type" blankOption="true" class="form-control digits" />-->
<!--							</div>-->
<!--						</div>-->
<!--					</div>-->
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('部门编码')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="deptCode" maxlength="20" class="form-control"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('部门')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="deptName" maxlength="20" class="form-control"/>
							</div>
						</div>
					</div>
					<#form:hidden path="batchs" /> <!-- 使用的批次 -->
<!--					<div class="col-xs-6">-->
<!--						<div class="form-group">-->
<!--							<label class="control-label col-sm-4" title="">-->
<!--								<span class="required hide">*</span> ${text('审批状态')}：<i class="fa icon-question hide"></i></label>-->
<!--							<div class="col-sm-8">-->
<!--								<#form:select path="approveState" dictType="st_approve_state" blankOption="true" class="form-control digits" />-->
<!--							</div>-->
<!--						</div>-->
<!--					</div>-->
<!--					<div class="col-xs-6">-->
<!--						<div class="form-group">-->
<!--							<label class="control-label col-sm-4" title="">-->
<!--								<span class="required hide">*</span> ${text('审批人编码')}：<i class="fa icon-question hide"></i></label>-->
<!--							<div class="col-sm-8">-->
<!--								<#form:input path="approveManCode" maxlength="20" class="form-control"/>-->
<!--							</div>-->
<!--						</div>-->
<!--					</div>-->
<!--					<div class="col-xs-6">-->
<!--						<div class="form-group">-->
<!--							<label class="control-label col-sm-4" title="">-->
<!--								<span class="required hide">*</span> ${text('审批人')}：<i class="fa icon-question hide"></i></label>-->
<!--							<div class="col-sm-8">-->
<!--								<#form:input path="approveManName" maxlength="5" class="form-control"/>-->
<!--							</div>-->
<!--						</div>-->
<!--					</div>-->
				</div>
				<div class="row">
					<div class="col-xs-12">
						<div class="form-group">
							<label class="control-label col-sm-2" title="">
								<span class="required hide">*</span> ${text('备注信息')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-10">
								<#form:textarea path="remarks" rows="4" maxlength="500" class="form-control"/>
							</div>
						</div>
					</div>
				</div>
				<h4 class="form-unit">${text('调拨单明细')}</h4>
				<div class="ml10 mr10">
					<table id="stInventoryBillDetailDataGrid"></table>
					<% if (hasPermi('st:stInventoryBill:edit')){ %>
						<a href="#" id="stInventoryBillDetailDataGridAddRowBtn" class="btn btn-primary btn-sm mt10 mb10" style="display: none"><i class="fa fa-plus"></i> ${text('增行')}</a>
					<% } %>
					<table id="batchDataGrid"></table>
				</div>
			</div>
			<div class="box-footer">
				<div class="row">
					<div class="col-sm-offset-2 col-sm-10">
<!--						<% if (hasPermi('st:stInventoryBill:edit')){ %>-->
<!--							<button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> ${text('保 存')}</button>&nbsp;-->
<!--						<% } %>-->
						<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
					</div>
				</div>
			</div>
		</#form:form>
	</div>
</div>
<% } %>
<script>
	$(function () {
		$("#stInventoryBillDetailDataGrid").on("click",".show-batch",function () {
			var batch = $(this).closest("tr").find("[name=batchNumber]").val();
			var bArr = batch.split(",");
			var tableList=[];
			for (var i = 0; i < bArr.length; i++) {
				var item0 = bArr[i];
				var item={
					id:i+1,
					batch:item0.split("_")[1],
					number:item0.split("_")[2],
				}
				tableList.push(item);
			}
			$('#batchDataGrid').dataGrid('setParam', {
				data:tableList,
				page: 1, rowNum: 5000
			}, true).dataGrid('reloadGrid');
		});
	})

	$('#batchDataGrid').dataGrid({
		// searchForm: $("#searchForm"),
		data:[],
		datatype: "local",
		columnModel: [
			{header: '主键', name: 'id', editable: true, hidden: true},
			{header: '${text("批号")}', name: 'batch', index: 'a.tally_date', width: 150, align: "center"},
			{header: '${text("数量")}', name: 'number', index: 'a.dept_code', width: 150, align: "left"},
		],
		// 加载成功后执行事件
		ajaxSuccess: function (data) {

		}
	});
	var allData;
//初始化调拨单明细DataGrid对象
$("#stInventoryBillDetailDataGrid").dataGrid({

	data: ${toJson(stInventoryBill.stInventoryBillDetailList)},
	datatype: "local", // 设置本地数据
	autoGridHeight: function(){return 'auto'}, // 设置自动高度

	// 设置数据表格列
	columnModel: [
		{header:'状态', name:'status', editable:true, hidden:true},
		{header:'主键', name:'id', editable:true, hidden:true},
		// {header:'${text("单据号")}', name:'billNo', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'20', 'class':'form-control'}},
		{header:'${text("物料名称")}', name:'materialName', width:150,
			editable:true, edittype:'select', editoptions:{'class':'form-control',
				items: $.merge([{productName:'&nbsp;',id:''}], ${materialRecordList}),
				itemLabel: 'productName', itemValue: 'id', dataInit: function(element){
					$(element).select2().on("change",function(){$(this).resetValid()});
					element.name="ignore_materialName";
					var name=element.name;
					var $closest = $(element).closest("tr");
					var id = $closest.attr("id");
					var index = $closest.find("td").first().html();
					$(element).attr("disabled",true);
					var code = '';
					var number = 0;
					var m_name = '';
					if(id.length>10) {//这么判断真他妈的槽
						for(var index in allData) {
							var item = allData[index];
							if(item.id == id) {
								// console.log(id, item);
								code = item.stProductRecord.productCode;//todo 还有半成品呢
								m_name = item.stProductRecord.productName;
								number = item.stSendNoticeBillDetail.number;
							}
						}
					}
					$(element).after("<input name='materialName' code='"+code+"' number='"+number+"' my-sort='"+index+"' m-name='"+m_name+"' value='"+element.value+"' hidden>");
					// $(element).after("<input name='batchNumber' hidden>");
				}
			}
			// ,formatter: function(val, obj, row, act) {
			// 	return obj;
			// }
		},
		{header:'${text("单位")}', name:'unit', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'36', 'class':'form-control',readonly:true}},
		{header:'${text("数量")}', name:'number', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'8', 'class':'form-control digits not0',readonly:true}},
		// {header:'${text("条码号")}', name:'barCode', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'20', 'class':'form-control'}},
		// {header:'${text("仓位")}', name:'warehousePosition', width:150,
		// 	editable:true, edittype:'select', editoptions:{'class':'form-control',
		// 		items: $.merge([{dictLabel:'&nbsp;',dictValue:''}], ${warehousePositionSettingList}),
		// 		itemLabel: 'warehouseName', itemValue: 'id', dataInit: function(element){
		// 			$(element).select2().on("change",function(){$(this).resetValid()});
		// 		}
		// 	}
		// },
		// {header:'${text("包装规格")}', name:'packType', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'20', 'class':'form-control'}},
		{header:'${text("件数")}', name:'caseNumber', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'8', 'class':'form-control digits',readonly:true}},
		{header:'${text("批号")}', name:'batchNumber', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control'},hidden:true},
		{header:'${text("批号")}', name:'primaryId', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'20', 'class':'form-control'},hidden:true},
		// {header:'${text("源单数量")}', name:'sourceBillNumber', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'20', 'class':'form-control',
		// 		dataInit: function(element){
		// 			$(element).attr("readonly", true);
		// 		}
		// 	}
		// },
		// {header:'${text("生产日期")}', name:'productDate', width:150,
		// 	formatter:'date', formatoptions:{srcformat:'Y-m-d H:i:s',newformat:'Y-m-d H:i:s'},
		// 	editable:true, edittype:'text', editoptions:{'class':'form-control laydate', 'readonly':'true',
		// 		dataInit: function(element){
		// 			laydate.render({elem:element, type:'datetime', format:'yyyy-MM-dd HH:mm'});
		// 		}
		// 	}
		// },
		// {header:'${text("保质期")}', name:'savedType', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'3', 'class':'form-control digits'}},
		// {header:'${text("到期日期")}', name:'passDate', width:150,
		// 	formatter:'date', formatoptions:{srcformat:'Y-m-d H:i:s',newformat:'Y-m-d H:i:s'},
		// 	editable:true, edittype:'text', editoptions:{'class':'form-control laydate', 'readonly':'true',
		// 		dataInit: function(element){
		// 			laydate.render({elem:element, type:'datetime', format:'yyyy-MM-dd HH:mm'});
		// 		}
		// 	}
		// },
		// {header:'${text("生产厂家")}', name:'productMaker', width:100,
		// 	editable:true, edittype:'select', editoptions:{'class':'form-control digits',
		// 		items: $.merge([{dictLabel:'&nbsp;',dictValue:''}], ${@DictUtils.getDictListJson('st_product_maker')}),
		// 		itemLabel: 'dictLabel', itemValue: 'dictValue', dataInit: function(element){
		// 			$(element).select2().on("change",function(){$(this).resetValid()});
		// 		}
		// 	}
		// },
		// {header:'${text("备注")}', name:'remarks', width:150, editable:true, edittype:'textarea', editoptions:{'maxlength':'255', 'class':'form-control', 'rows':'1'}},
		{header:'${text("父 id")}', name:'parentId.id', editable:true, hidden:true},
			<% if(bill_type! =='diaobo'){ %>

		{header:'${text("库存数量")}', name:'inventoryNumber', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'8', 'class':'form-control digits'}},
		{header:'${text("调出仓位")}', name:'allotOutWarehouse', width:150,
			editable:true, edittype:'select', editoptions:{'class':'form-control',
				items: $.merge([{dictLabel:'&nbsp;',dictValue:''}], ${warehousePositionSettingList}),
				itemLabel: 'warehouseName', itemValue: 'id', dataInit: function(element){
					$(element).select2().on("change",function(){$(this).resetValid()});
				}
			}
		},
		{header:'${text("调入仓位")}', name:'allotInWarehouse', width:150,
			editable:true, edittype:'select', editoptions:{'class':'form-control',
				items: $.merge([{dictLabel:'&nbsp;',dictValue:''}], ${warehousePositionSettingList}),
				itemLabel: 'warehouseName', itemValue: 'id', dataInit: function(element){
					$(element).select2().on("change",function(){$(this).resetValid()});
				}
			}
		},
		{header:'${text("调拨数量")}', name:'allotNumber', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'8', 'class':'form-control digits'}},
		<% } %>
		{header:'${text("操作")}', name:'actions', width:80, sortable:false, fixed:true, formatter: function(val, obj, row, act){
			var actions = [];
			if (val == 'new'){
				actions.push('<a href="#" class="del" onclick="$(\'#stInventoryBillDetailDataGrid\').dataGrid(\'delRowData\',\''+obj.rowId+'\')"><i class="fa fa-trash-o"></i></a>&nbsp;');
				actions.push('<a href="#" class="show-batch" ><i class="fa fa-bars"></i></a>&nbsp;');
			}else{
				actions.push('<a href="#" class="del" onclick="$(\'#stInventoryBillDetailDataGrid\').dataGrid(\'setRowData\',\''+obj.rowId+'\',null,{display:\'none\'});$(\'#'+obj.rowId+'_status\').val(\''+Global.STATUS_DELETE+'\');"><i class="fa fa-trash-o"></i></a>&nbsp;');
				actions.push('<a href="#" class="show-batch" ><i class="fa fa-bars"></i></a>&nbsp;');
			}
			return actions.join('');
		}, editoptions: {defaultValue: 'new'}}
	],
	shrinkToFit: false,
	// 编辑表格参数
	editGrid: true,				// 是否是编辑表格
	editGridInitRowNum: 1,		// 编辑表格的初始化新增行数
	editGridAddRowBtn: $('#stInventoryBillDetailDataGridAddRowBtn'),	// 子表增行按钮
	editGridAddRowInitData: {id: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据

	// 编辑表格的提交数据参数
	editGridInputFormListName: 'stInventoryBillDetailList', // 提交的数据列表名
	editGridInputFormListAttrs: 'status,id,billNo,materialName,unit,batchNumber,barCode,warehousePosition,packType,number,productDate,savedType,passDate,productMaker,remarks,parentId.id,inventoryNumber,allotOutWarehouse,allotInWarehouse,allotNumber,sourceBillNumber,caseNumber,primaryId', // 提交数据列表的属性字段

	// 加载成功后执行事件
	ajaxSuccess: function(data){
		// console.log("ajaxSuccess");
		allData=data.rows;
		addLength=data.rows.length;
	},
	// onSelectRow: function(id, isSelect, event){
	//
	// },
});
</script>
<script>
$("#inputForm").validate({
	submitHandler: function(form){
		var myBreak=0;
		$.each($(".not0"),function (i, item) {
			if (0 == $(item).val()) {
				js.showMessage("数量不能为0");
				myBreak = 1;
				return;
			}
		});
		if(myBreak) return;
		js.ajaxSubmitForm($(form), function(data){
			var id = data.data.id;
			// $("#id").val(id);
			console.info(id);
			refresh(id);
			js.showMessage(data.message);
			// if(data.result == Global.TRUE){
			// 	js.closeCurrentTabPage(function(contentWindow){
			// 		contentWindow.page();
			// 	});
			// }

		}, "json");
    }
});
</script>